<?php
// ------------------------------------------------------------------------
// |@Author       : Jarmin <edshop@qq.com>
// |@----------------------------------------------------------------------
// |@Date         : 2023-06-24 19:33:57
// |@----------------------------------------------------------------------
// |@LastEditTime : 2023-06-24 19:36:13
// |@----------------------------------------------------------------------
// |@LastEditors  : Jarmin <jarmin@ladmin.cn>
// |@----------------------------------------------------------------------
// |@Description  : 
// |@----------------------------------------------------------------------
// |@FilePath     : Role.php
// |@----------------------------------------------------------------------
// |@Copyright (c) 2023 http://www.ladmin.cn   All rights reserved. 
// ------------------------------------------------------------------------
namespace app\setting\validate;

use think\Validate;

/**
 * 角色验证类，用于实现角色相关的验证操作。
 */
class Role extends Validate
{
    protected $rule     =   [
        'name'                 => 'require|max:50|unique:system_role',
        'alias'                => 'require|max:50|unique:system_role',
        'ids'                  => 'require|array',
        'role_ids'             => 'require|array',
        'menu_ids'             => 'require|array',
    ];
    
    protected $message  =   [
        'name.require'         => 'role.name_require',
        'name.max'             => 'role.name_max',
        'name.unique'          => 'role.name_unique',
        'alias.require'        => 'role.alias_require',
        'alias.max'            => 'role.alias_max',
        'alias.unique'         => 'role.alias_unique',
        'ids.require'          => 'role.ids_require',
        'ids.array'            => 'role.ids_array',
        'role_ids.require'     => 'role.role_ids_require',
        'role_ids.array'       => 'role.role_ids_array',
        'menu_ids.require'     => 'role.menu_ids_require',
        'menu_ids.array'       => 'role.menu_ids_array',
    ];

    // add 验证场景定义
    public function sceneAdd()
    {
    	return $this->only(['name','alias']);
    }

    // edit 验证场景定义
    public function sceneEdit()
    {
    	return $this->only(['name','alias']);
    }

    // allot 验证场景定义
    public function sceneAllot()
    {
    	return $this->only(['role_ids', 'menu_ids']);
    }

    // remove 验证场景定义
    public function sceneDelete()
    {
    	return $this->only(['ids']);
    }
}